package com.hospital.hospitalsystem.modules.medicine.controller;

import com.hospital.hospitalsystem.base.BaseResponse;
import com.hospital.hospitalsystem.base.PageData;
import com.hospital.hospitalsystem.config.TokenVerify;
import com.hospital.hospitalsystem.modules.doctor.dto.PrescriptionReq;
import com.hospital.hospitalsystem.modules.medicine.biz.HospitalMedicalBiz;
import com.hospital.hospitalsystem.modules.medicine.dto.*;
import com.hospital.hospitalsystem.utils.LoginUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author qiancheng@cqxyy.net
 * @date 2023/4/4
 */
@RestController
@RequestMapping("/medicine")
@Api(tags = "医院药品管理")
@Validated
public class HospitalMedicalController {
    @Autowired
    private HospitalMedicalBiz hospitalMedicalBiz;

    @Autowired
    private LoginUtils loginUtils;

    @ApiOperation(value = "添加药品信息")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse addMedical(@RequestBody HospitalMedicalReq req){
        String operateUuid = loginUtils.getUser().getUserUuid();
        hospitalMedicalBiz.addMedical(req,operateUuid);
        return BaseResponse.success();
    };

    @ApiOperation(value = "删除药品信息")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse deleteMedical(@RequestBody HospitalMedicalReq req){
        String operateUuid = loginUtils.getUser().getUserUuid();
        hospitalMedicalBiz.deleteMedical(req,operateUuid);
        return BaseResponse.success();
    };

    @ApiOperation(value = "根据uuid获取药品信息")
    @RequestMapping(path = "/get-one",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse getOneMedical(@RequestBody HospitalMedicalReq req){
        HospitalMedicalRsp result = hospitalMedicalBiz.getOneMedical(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "根据uuid更新药品信息")
    @RequestMapping(path = "/update",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse updateMedical(@RequestBody HospitalMedicalReq req){
        String operateUuid = loginUtils.getUser().getUserUuid();
        hospitalMedicalBiz.updateMedical(req,operateUuid);
        return BaseResponse.success();
    };

    @ApiOperation(value = "获取药品信息")
    @RequestMapping(path = "/get",method = RequestMethod.POST)
    @TokenVerify(type = "medicine,doctor")
    public BaseResponse<PageData<HospitalMedicalRsp>> getMedical(@RequestBody HospitalMedicalListReq req){
        PageData<HospitalMedicalRsp> result = hospitalMedicalBiz.getMedical(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "根据uuid入库药品信息")
    @RequestMapping(path = "/storage",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse storageMedical(@RequestBody HospitalMedicalReq req){
        String operateUuid = loginUtils.getUser().getUserUuid();
        hospitalMedicalBiz.storageMedical(req,operateUuid);
        return BaseResponse.success();
    };

    @ApiOperation(value = "检查药品库存")
    @RequestMapping(path = "/check-storage",method = RequestMethod.POST)
    @TokenVerify(type = "doctor,user,medicine")
    public BaseResponse checkStorage(@RequestBody CheckStorageReq req){
        List<CheckStorageRsp> list = hospitalMedicalBiz.checkStorage(req);
        return BaseResponse.success(list);
    };

    @ApiOperation(value = "根据药方出库药品")
    @RequestMapping(path = "/out-storage",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse prescriptionOut(@RequestBody PrescriptionOutReq req){
        req.setOperatorUuid(loginUtils.getUser().getUserUuid());
        hospitalMedicalBiz.prescriptionOut(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查看药方(仅限当日)")
    @RequestMapping(path = "/show-prescription",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse showPrescription(@RequestBody ShowPrescriptionReq req){
        List<ShowPrescriptionRsp> result = hospitalMedicalBiz.showPrescription(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "完成抓药")
    @RequestMapping(path = "/finish",method = RequestMethod.POST)
    @TokenVerify(type = "medicine")
    public BaseResponse finish(@RequestBody PrescriptionReq req){
        hospitalMedicalBiz.finish(req);
        return BaseResponse.success();
    };
}
